package com.sskj.level.presenter;

import android.text.TextUtils;

import com.lzy.okgo.model.Response;
import com.sskj.level.bean.TradeInfoBean;
import com.sskj.level.http.HttpConfig;
import com.sskj.level.ui.fragment.LevelFragment;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.StockCoinBean;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class LevelFragmentPresenter extends BasePresenter<LevelFragment> {

    public void getProduct(String code) {
        httpService.getProduct(code)
                .execute(new JsonCallBack<HttpData<List<StockCoinBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<StockCoinBean>>> response) {
                        HttpData<List<StockCoinBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUI(httpData.getData().get(0).getStockProductVO());
                        }
                    }
                });
    }

    public void getRisk() {
        if (TextUtils.isEmpty(SPUtil.get(SPConfig.ID, ""))) {
            mView.updateRisk(null);
            return;
        }
        httpService.getRisk()
                .tag(this)
                .execute(new JsonCallBack<HttpData<TradeInfoBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<TradeInfoBean>> response) {
                        HttpData<TradeInfoBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateRisk(httpData.getData());
                        }
                    }
                });
    }
}
